<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minOperations = function (nums, numsDivide) {
      nums.sort((a, b) => a - b);
      let ans = -1;
      for (let i = 0; i < nums.length; i++) {
        let cur = nums[i], can = true;
        if (i > 0 && cur === nums[i - 1]) { // 去重
          continue;
        }
        for (const num of numsDivide) {
          if (num % cur) { // 不能整除
            can = false;
          }
        }
        if (can) {
          return i;
        }
      }
      return ans;
    };
    console.log(minOperations([2, 3, 2, 4, 3], [9, 6, 9, 3, 15]));
  </script>
</body>

</html>